@echo off
echo ===================================
echo    FinData Admin System Startup
echo ===================================
echo.

echo Checking environment...
where dotnet >nul 2>nul
if %errorlevel% neq 0 (
    echo Error: dotnet command not found. Please install .NET SDK
    echo You can download it from https://dotnet.microsoft.com/download
    pause
    exit /b 1
)

echo.
echo Starting MariaDB service...

REM Try to start MariaDB service if installed
sc query "MariaDB" > nul
if %ERRORLEVEL% EQU 0 (
    REM Service exists, check if it's running
    sc query "MariaDB" | findstr "RUNNING" > nul
    if %ERRORLEVEL% EQU 0 (
        echo MariaDB service is already running
    ) else (
        echo Starting MariaDB service...
        net start MariaDB
    )
) else (
    REM Service doesn't exist, try to start from installation directory
    if exist "..\MariaDB 10.5\bin\mysqld.exe" (
        echo Starting MariaDB from directory...
        start /b "MariaDB" "..\MariaDB 10.5\bin\mysqld.exe" --console --port=3306 --datadir="..\MariaDB 10.5\data"
        echo MariaDB started
    ) else (
        echo MariaDB executable not found
        echo Please ensure MariaDB is properly installed or start it manually
    )
)

echo.
echo Waiting 5 seconds to ensure MariaDB is fully started...
timeout /t 5 /nobreak > nul

echo.
echo Starting FinData Admin System...
echo Access URL: http://localhost:8002
echo Admin login: http://localhost:8002/admin/login
echo Supervisor login: http://localhost:8002/supervisor/login
echo.
echo Press Ctrl+C to stop the service
echo.

dotnet run --urls=http://localhost:8002

echo.
echo Service stopped

pause 